<template>
    <div>
        <h1><i>东软云医院HIS系统</i></h1>
        <h2>系统信息--结算类别管理</h2><hr>
        <div>
            <el-container>
                <el-header>
                    <el-row>
                        <el-col :span="24"></el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8"><el-input v-model="input" placeholder="请输入内容"></el-input></el-col>
                        <el-col :span="8"><el-button type="primary" @click="queryAll()"><i class="el-icon-view"></i>查看结算类别</el-button></el-col>
                        <el-col :span="8"><el-button type="primary" @click="toaddSettleCategory()"><i class="el-icon-edit"></i>新增结算类别</el-button></el-col>
                        <!-- 当dialogVisible = true，弹出窗体显示内容 -->
                        <el-dialog :visible.sync="dialogVisible">
                            <span>新增结算类别</span>
                            <el-form :model="addSettleCategoryForm">
                                <el-form-item label="类别编码: " >
                                    <el-input v-model="addSettleCategoryForm.settleCode"></el-input>
                                </el-form-item>
                            </el-form>
                            <el-form :model="addSettleCategoryForm">
                                <el-form-item label="类别名称: " >
                                    <el-input v-model="addSettleCategoryForm.settleName"></el-input>
                                </el-form-item>
                            </el-form>
                            <el-form :model="addSettleCategoryForm">
                                <el-form-item label="显示顺序号: " >
                                    <el-input v-model="addSettleCategoryForm.sequenceNo"></el-input>
                                </el-form-item>
                            </el-form>
                            <span slot="footer" class="dialog-footer">
                                <el-button @click="dialogVisible = false">取 消</el-button>
                                <el-button type="primary" @click="addNewSettleCategory()">确 定</el-button>
                            </span>
                        </el-dialog>
                    </el-row>
                </el-header>
            </el-container>
        </div>

        <!-- 表格显示 -->
        <div>
            <el-container>
                <el-header>
                    <el-row>
                        <el-col :span="24">
                            <el-table :data="Settletable" style="width: 100%">
                                <el-table-column label="显示顺序号" width="180" prop="SequenceNo"></el-table-column>
                                <el-table-column label="类别编码" width="180" prop="SettleCode"></el-table-column>
                                <el-table-column label="类别名称" width="180" prop="SettleName"></el-table-column>

                                <el-table-column label="操作">
                                    <template slot-scope="scope"><i class="el-icon-edit-outline"></i>
                                        <el-button size="mini" @click="updateAndselect(scope.$index, scope.row)">编辑</el-button>
                                        <!-- 当dialogVisible = true，弹出窗体显示内容 -->
                                        <el-dialog :visible.sync="updatedialogVisiblet">
                                            <span>修改结算类别</span>
                                            <el-form :model="updateSettleForm">
                                                <el-form-item label="类别编码: " >
                                                    <el-input v-model="updateSettleForm.settleCode"></el-input>
                                                </el-form-item>
                                            </el-form>
                                            <el-form :model="updateSettleForm">
                                                <el-form-item label="类别名称:  " >
                                                    <el-input v-model="updateSettleForm.settleName"></el-input>
                                                </el-form-item>
                                            </el-form>
                                            <el-form :model="updateSettleForm">
                                                <el-form-item label="显示顺序号:  " >
                                                    <el-input v-model="updateSettleForm.sequenceNo"></el-input>
                                                </el-form-item>
                                            </el-form>
                                            <span slot="footer" class="dialog-footer">
                                                <el-button @click="updatedialogVisiblet = false">取 消</el-button>
                                                <el-button type="primary" @click="updateNewSettle()">确 定</el-button>
                                            </span>
                                        </el-dialog>
                                        <el-button size="mini" type="danger"@click="handleDelete(scope.$index, scope.row)">删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-col :span="24">
                            <el-pagination
                             background
                             layout="prev, pager, next"
                              :total="totalNumber"
                              :hide-on-single-page="pageShow"
                              @current-change="pageChange"><!-- 页码改变 -->
                            </el-pagination>
                        </el-col>
                    </el-row>
                </el-header>
            </el-container>
        </div>


        <div>

        </div>
    </div>
</template>

<script>
  /* 将axios独立成为函数--导入 */
  import {postRequest} from '../../utils/ajaxapi'
  import {getRequest} from '../../utils/ajaxapi'

  export default {
      data(){
          return{
              input:'',
              totalNumber:300,
              dialogVisible:false,
              updatedialogVisiblet:false,
              addSettleCategoryForm:{
                  settleCode:'',//类别编码
                  settleName:'',//类别名称
                  sequenceNo:''//显示顺序号
              },
              updateSettleForm:{
                  settleCode:'',//类别编码
                  settleName:'',//类别名称
                  sequenceNo:''//显示顺序号
              },
              Settletable:[{
                  SequenceNo:'110',//显示顺序号
                  SettleCode:'110',//类别编码
                  SettleName:'警察' //类别名称
              }]
          }
      },
      methods:{
          toaddSettleCategory(){
              let _this = this;
               _this.dialogVisible = true;//新增窗体打开
          },
          /* 新增数据 */
          addNewSettleCategory(){
              let _this = this;
              postRequest("/neuhis/sys/settle/addNew",this.addSettleCategoryForm)
              .then(function(response){
                  alert(_this.addSettleCategoryForm.settleName);
                  _this.addSettleCategoryForm.settleName = response.data.settleName;
              })
              _this.dialogVisible = false;
          },
          /* 查询所有数据 */
          queryAll(){
              if(this.input == null){
               this.input = '';
              }
              alert(this.input);
              this.toselectSettleCategory(1,10,this.input);
          },
          //根据输入的内容查找
          toselectSettleCategory(pageNumber,pageSize,settleN){
              let _this = this;
              getRequest("/neuhis/sys/settle/getSettles?pageNumber="+pageNumber+"&pageSize="+pageSize+"&SettleName="+settleN)
              .then(function(response){
                  _this.Settletable = response.data.map;
                  _this.totalNumber = response.data.totalNumber;
              });
          },
          //页数
          pageChange(pageNum){//回调参数,代表当前页数，
              alert(pageNum);
              if(this.input == null){
                this.input = '';
              }
              this.toselectSettleCategory(pageNum,10,'');
          },
          /* 修改数据 */
          updateAndselect(index,row){
              let _this = this;
              _this.updatedialogVisiblet = true;
              _this.updateSettleForm.sequenceNo = this.Settletable[index].SequenceNo;
              _this.updateSettleForm.settleCode = this.Settletable[index].SettleCode;
              _this.updateSettleForm.settleName = this.Settletable[index].SettleName;
          }
      }
  }
  </script>

<style>
</style>
